from .config import config

# redis 配置
REDIS_HOST = config.redis.host
REDIS_PORT = config.redis.port
REDIS_PASSWORD = config.redis.password

# 限流使用的cache
THROTTLE_CACHE_NAME = "throttle"
# 默认的cache
DEFAULT_CACHE_NAME = "default"


# 获取cache的配置
CACHES = {
    f"{DEFAULT_CACHE_NAME}": {
        "BACKEND": "django_redis.cache.RedisCache",
        # 使用的redis数据
        "LOCATION": f"redis://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}/0",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",  # 必选
        },
        "TIMEOUT": 60,  # 默认60秒
    },
    f"{THROTTLE_CACHE_NAME}": {
        "BACKEND": "django_redis.cache.RedisCache",
        # 使用的redis数据
        "LOCATION": f"redis://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}/1",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",  # 必选
            # 连接池配置
            "CONNECTION_POOL_KWARGS": {
                "max_connections": 50,  # 连接池最大连接数
                "retry_on_timeout": True,  # 超时时重试
                # "encoding": "utf-8",     # 可选：编码
                # "socket_connect_timeout": 5, # 连接超时
                # "socket_timeout": 5,         # 读写超时
            },
            # 可选：序列化方式
            # "SERIALIZER": "django_redis.serializers.json.JSONSerializer",
            # 或
            # "SERIALIZER": "django_redis.serializers.msgpack.MSGPackSerializer",
        },
        # 可选：设置缓存键前缀，避免不同项目冲突
        # "KEY_PREFIX": "myapp",
        # 可选：设置缓存的默认超时时间60秒
        "TIMEOUT": 60,
    },
}


"""
# settings.py下
from base_config.cache_config import CACHES
CACHES = CACHES
"""
